lapis = require "lapis"

import respond_to from require "lapis.application"

-- using redis database
redis = require "resty.redis"
red = redis\new!

-- using websocket
wsc = require "libs.wsc"

-- using cjson
cjson = require "cjson"
-- Main entry of lapis application

class ReplApplication extends lapis.Application

    [repl: "/repl"]: =>
        render: true

    [socket: "/socket"]: =>
        render: true

    [wss: "/wss"]: =>
        @r1, err = wsc\connect "ws://108.61.163.61:8080/s"
        @r2, err = wsc\send_text "Websocket rocks! xing wenju" 
        @data, typ, err = wsc\recv_frame!
        wsc\close
        render: "repl"

    [redis: "/redis"]: =>
        red\connect "127.0.0.1",6379
        red\set "name",cjson.encode wsc
        red\close!
        render: "repl"
